package com.ruoyi.wvp.controller;

import java.util.List;
import java.util.Date;

import com.ruoyi.common.utils.file.ImageUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wvp.domain.SurveillanceEvent;
import com.ruoyi.wvp.service.ISurveillanceEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.enums.DeletedEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * ai摄像头事件Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/wvp/surveillanceEvent")
@Tag(name = "【ai摄像头事件】管理")
public class SurveillanceEventController extends BaseController{
    @Autowired
    private ISurveillanceEventService surveillanceEventService;

    /**
     * 查询ai摄像头事件列表
     */
    @Operation(summary = "查询ai摄像头事件列表")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveillanceEvent surveillanceEvent) {
        Page<SurveillanceEvent> page = getPage();
        Page<SurveillanceEvent> surveillanceEventPage = surveillanceEventService.pageList(page, surveillanceEvent);
        return getTableDataInfo(page);
    }


    /**
     * 导出ai摄像头事件列表
     */
    @Operation(summary = "导出ai摄像头事件列表")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:export')")
    @Log(title = "ai摄像头事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void exportAll(HttpServletResponse response,SurveillanceEvent surveillanceEvent){
        List<SurveillanceEvent> list = surveillanceEventService.listAll(surveillanceEvent);
        ExcelUtil<SurveillanceEvent> util = new ExcelUtil<SurveillanceEvent>(SurveillanceEvent.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取ai摄像头事件详细信息
     */
    @Operation(summary = "获取ai摄像头事件详细信息")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(surveillanceEventService.getById(id));
    }

    /**
     * 新增ai摄像头事件
     */
    @Operation(summary = "新增ai摄像头事件")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:add')")
    @Log(title = "ai摄像头事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveillanceEvent surveillanceEvent){
        surveillanceEvent.setDeleted(DeletedEnum.NOMAL.getValue());
        surveillanceEvent.setCreateBy(getUsername());
        surveillanceEvent.setCreateTime(new Date());
        return toAjax(surveillanceEventService.save(surveillanceEvent));
    }

    /**
     * 修改ai摄像头事件
     */
    @Operation(summary = "修改ai摄像头事件")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:edit')")
    @Log(title = "ai摄像头事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveillanceEvent surveillanceEvent){
         surveillanceEvent.setUpdateBy(getUsername());
         surveillanceEvent.setUpdateTime(new Date());
        return toAjax(surveillanceEventService.updateById(surveillanceEvent));
    }

    /**
     * 删除ai摄像头事件
     */
    @Operation(summary = "删除ai摄像头事件")
    @PreAuthorize("@ss.hasPermi('wvp:surveillanceEvent:remove')")
    @Log(title = "ai摄像头事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) {
        QueryWrapper<SurveillanceEvent> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",List.of(ids));
        SurveillanceEvent surveillanceEvent = new SurveillanceEvent();
        surveillanceEvent.setUpdateTime(new Date());
        surveillanceEvent.setUpdateBy(getLoginUser().getUser().getUserName());
        surveillanceEvent.setDeleted(DeletedEnum.DELETED.getValue());
        return toAjax(surveillanceEventService.update(surveillanceEvent,queryWrapper));
    }

}
